package com.junmiao.A;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class MatchFile {

	public static int count = 1;

	public static void main(String[] args) throws IOException {
		File f = new File("c:\\1111.txt");
	//	File f1 = new File("c:\\2222.txt");
		File f2 = new File("c:\\3333.txt");

		FileReader fr = new FileReader(f);
///		FileReader fr1 = new FileReader(f1);
		FileWriter fw = new FileWriter(f2);

		BufferedReader br1 = new BufferedReader(fr);

		BufferedWriter bw = new BufferedWriter(fw);

		String s1, s2;
		while ((s1 = br1.readLine()) != null) {
			String[] tmp = s1.split(":");
			if (tmp != null && tmp.length == 3) {
				String tmp1 = tmp[1].trim();
				File f1 = new File("c:\\2222.txt");
				FileReader fr1 = new FileReader(f1);
				BufferedReader br2 = new BufferedReader(fr1);
				while ((s2 = br2.readLine()) != null) {
					String[] tmp3 = s2.split(":");
					if (tmp3 != null && tmp3.length == 3) {
						String tmp2 = tmp3[1].trim();
						if (tmp1.equalsIgnoreCase(tmp2)) {
							bw.write(count + ":" + tmp[1] + "\n");
							count += 1;
						}
					}	
				}
				br2.close();
				fr1.close();
				f1 = null;
				fr1 = null;
				br2 =  null;
				
			}
		}

		bw.flush();
		bw.close();
		fw.close();

		br1.close();

	}
}
